package com.ordobill.webapp.action;

import java.util.ArrayList;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.commons.logging.*;
import com.ibatis.sqlmap.client.*;
import com.ordobill.webapp.beans.Member;
import com.ordobill.webapp.common.SqlMapClientManager;
import org.apache.struts.actions.*;

public class MypageAction extends DispatchAction{
	
	@SuppressWarnings("unused")
    private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
	private SqlMapClient sqlMap = SqlMapClientManager.getSqlMapClient();

	public ActionForward info(ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
		Member memberForm = (Member)form;
		Member memberData = (Member)sqlMap.queryForObject("Member.list", memberForm);
		
		request.setAttribute("memberData", memberData);

        return mapping.findForward("info");
    }
	
	public ActionForward update(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
		Member memberForm = (Member)form;
		ActionMessages msg = new ActionMessages();
		int message = -1;
		    message = (Integer)sqlMap.update("Member.memberUpdate", memberForm);
		       
	    if(message == 0){
	        msg.add("message", new ActionMessage("저장에 실패했습니다."));
	    }else if(message > 0){
	        msg.add("message", new ActionMessage("저장에 성공했습니다."));
	    }
	        
		Member memberData = (Member)sqlMap.queryForObject("Member.list", memberForm);
		saveMessages(request, msg);
		request.setAttribute("memberData", memberData);
        return mapping.findForward("update");
    }
}
